home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
pl1
/
pi
< prev
next >
Wrap
Text File
|
1989-04-22
|
5KB
|
221 lines
CLRSCR;
PRINT(SYSPRINT,REPEAT(' ',30),'Computation of Pi');
PUTCRLF; PUTCRLF; PUTCRLF;
n=1;
DO WHILE(n > 0);
PRINT(SYSPRINT,'Number of decimal places (0 to exit)? ');
n=getint;
IF n > 0 THEN
DO;
n_plus_1=n+1;
PRINT(SYSPRINT,'pi = ');
m=n+3;
i=2*m-1;
d1=25;
d2=239;
k=0;
k_mod_5=-1;
group_mod_12=1;
p(1)=0;
p(2)=0;
p(3)=0;
x(1)=3;
x(2)=2;
x2(1)=4;
x2(2)=0;
j=3;
DO WHILE(j <= m);
p(j)=0;
x(j)=0;
x2(j)=0;
j=j+1;
END;
r=0;
j=1;
DO WHILE(j <= m);
v=r*10+x2(j);
jd1=v/d2;
x2(j)=jd1;
r=v-d2*jd1;
j=j+1;
END;
d=1;
DO WHILE(d <= i);
r=0;
j=1;
DO WHILE(j<=m);
v=r*10+x(j);
jd1=v/d;
y(j)=jd1;
r=v-d*jd1;
j=j+1;
END;
j=m;
DO WHILE(j >= 1);
p(j)=p(j)+y(j);
IF p(j) > 9 THEN
DO;
p(j)=p(j)-10;
p(j-1)=p(j-1)+1;
END;
j=j-1;
END;
r=0;
j=1;
DO WHILE(j <= m);
v=r*10+x(j);
jd1=v/d1;
x(j)=jd1;
r=v-d1*jd1;
j=j+1;
END;
dd=d+2;
r=0;
j=1;
DO WHILE(j<=m);
v=r*10+x(j);
jd1=v/dd;
y(j)=jd1;
r=v-dd*jd1;
j=j+1;
END;
j=m;
DO WHILE(j >= 1);
p(j)=p(j)-y(j);
IF p(j) < 0 THEN
DO;
p(j)=p(j)+10;
p(j-1)=p(j-1)-1;
END;
j=j-1;
END;
r=0;
j=1;
DO WHILE(j <= m);
v=r*10+x(j);
jd1=v/d1;
x(j)=jd1;
r=v-d1*jd1;
j=j+1;
END;
r=0;
j=1;
DO WHILE(j <= m);
v=r*10+x2(j);
jd1=v/d;
y(j)=jd1;
r=v-d*jd1;
j=j+1;
END;
j=m;
DO WHILE(j >= 1);
p(j)=p(j)-y(j);
IF p(j) < 0 THEN
DO;
p(j)=p(j)+10;
p(j-1)=p(j-1)-1;
END;
j=j-1;
END;
r=0;
j=1;
DO WHILE(j <= m);
v=r*10+x2(j);
jd1=v/d2;
x2(j)=jd1;
r=v-d2*jd1;
j=j+1;
END;
r=0;
j=1;
DO WHILE(j <= m);
v=r*10+x2(j);
jd1=v/d2;
x2(j)=jd1;
r=v-d2*jd1;
j=j+1;
END;
dd=d+2;
r=0;
j=1;
DO WHILE(j <= m);
v=r*10+x2(j);
jd1=v/dd;
y(j)=jd1;
r=v-dd*jd1;
j=j+1;
END;
j=m;
DO WHILE(j >= 1);
p(j)=p(j)+y(j);
IF p(j) > 9 THEN
DO;
p(j)=p(j)-10;
p(j-1)=p(j-1)+1;
END;
j=j-1;
END;
r=0;
j=1;
DO WHILE(j <= m);
v=r*10+x2(j);
jd1=v/d2;
x2(j)=jd1;
r=v-d2*jd1;
j=j+1;
END;
r=0;
j=1;
DO WHILE(j <= m);
v=r*10+x2(j);
jd1=v/d2;
x2(j)=jd1;
r=v-d2*jd1;
j=j+1;
END;
k=k+1;
IF k <= n_plus_1 THEN
DO;
k_mod_5=k_mod_5+1;
IF k_mod_5 > 5 THEN
DO;
k_mod_5=1;
group_mod_12=group_mod_12+1;
IF group_mod_12 > 12 THEN
DO;
group_mod_12=1;
PUTCRLF(SYSPRINT);
PRINT(SYSPRINT,' ');
END;
ELSE
PRINT(SYSPRINT,' ');
END;
PRINT(SYSPRINT,p(k));
IF k = 1 THEN
PRINT(SYSPRINT,'.');
END;
k=k+1;
IF k <= n_plus_1 THEN
DO;
k_mod_5=k_mod_5+1;
IF k_mod_5 > 5 THEN
DO;
k_mod_5=1;
group_mod_12=group_mod_12+1;
IF group_mod_12 > 12 THEN
DO;
group_mod_12=1;
PUTCRLF(SYSPRINT);
PRINT(SYSPRINT,' ');
END;
ELSE
PRINT(SYSPRINT,' ');
END;
PRINT(SYSPRINT,p(k));
END;
d=d+4;
END;
PUTCRLF(SYSPRINT);
END;
END;